<?php
    // product menu
    class SlideshowModel
    {
        public function __construct(PDO $pdo) {
            $this->pdo = $pdo;
        }
        public function getAllSlideshow()
        {
            $sql = "SELECT * FROM set_slideshow";
            $sth = $this->pdo->prepare($sql);
            $sth->execute();
            $result = $sth->fetchAll();
            return $result;             
        }
        public function insertSlideshow($arrayPost)
        {
            $sql = "INSERT INTO set_slideshow (
                name,
                url,
               	photo,
               	active
                ) 
                VALUES (
                :name,
                :url,
               	:photo,
               	:active
                )";
            $sth = $this->pdo->prepare($sql);
            $result = $sth->execute(array(
                                ':name'                =>$arrayPost['name'],
                                ':url'               =>$arrayPost['url'],
                                ':photo'             =>$arrayPost['photo'],
                                ':active'              =>isset($arrayPost['active'])?1:0,                         
                        ));
                            
            return true;  
        }
        public function editSlideshow($arrayPost)
        {
            $sql = "UPDATE set_slideshow 
                    SET name=?, url=?, photo=?, active=?
            		WHERE id=?";
            $sth = $this->pdo->prepare($sql);
            $result = $sth->execute(array($arrayPost['name'],$arrayPost['url'],$arrayPost['photo'],
            isset($arrayPost['active'])?1:0,$arrayPost['id']));               
            return true; 
        }
        public function getSlideshowByID($id){
            $sql = "SELECT * FROM set_slideshow WHERE id=$id limit 1";
            $sth = $this->pdo->prepare($sql);
            $sth->execute();
            $result = $sth->fetch();
            return $result;            
        }
        public function deleteSlideshow($id)
        {
            $sql = "DELETE FROM `set_slideshow` WHERE id=$id";
            $sth = $this->pdo->prepare($sql);
            $sth->execute();            
        }               
    }